package cheme.Application;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import cheme.Application.ProjectSpaceModel.ChemeProjectModel;
import cheme.Application.actions.ShowConsoleAction;
import cheme.ProcessEditor.ChemeFileInput;
import cheme.ProcessEditor.ProcessEditor;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor
{
	public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer)
	{
		super(configurer);
	}

	public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer)
	{
		return new ApplicationActionBarAdvisor(configurer);
	}

	public void preWindowOpen()
	{
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		configurer.setInitialSize(new Point(800, 550));
		configurer.setShowMenuBar(true);
		configurer.setShowCoolBar(true);
		configurer.setShowStatusLine(true);		
		
		configurer.setTitle("ChemProV"); // PA Title of the Application Changed
	}
	
	@Override
	public void postWindowOpen()
	{
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		ChemeFileInput input = ChemeProjectModel.getInstance().getNewFile();
		
		configurer.getWindow().getShell().setMaximized(true);
		configurer.getWindow().getShell().setImage(ChemeApplicationConstants.CHEME_ICON_16.createImage());
		
		try
		{
			configurer.getWindow().getActivePage().openEditor(input, ProcessEditor.ID);
			

			
			// PA Change to add console view
			ShowConsoleAction consoleObject = new ShowConsoleAction(configurer.getWindow());
			if (null != consoleObject)
			{
				//consoleObject.createView();
			}
			
		}
		catch(Exception e)
		{
			MessageDialog.openInformation(null, getClass().getName(), e.getMessage());
			e.printStackTrace();
		}
				
		super.postWindowOpen();
	}
}
